﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FileSaveItemComponent : MonoBehaviour 
{

    [SerializeField]
    UITexture texture;

    [SerializeField]
    UILabel label;

    public FileScrollViewComponent fileScrollViewComponent;
    public void Show(Texture2D img,string name, FileScrollViewComponent fileScrollViewComponent)
    {
        this.texture.mainTexture = img;
        this.label.text = name;
        this.fileScrollViewComponent = fileScrollViewComponent;
    }

    public void OnClick()
    {
        if (fileScrollViewComponent != null && label != null)
        {
            switch (fileScrollViewComponent.isRead)
            {
                case FileScrollViewComponent.FileOperationType.Read:
                    UIComponentMastermind.instance.ShowYesOrNo(
                        "是否[EEE12EFF]读取[-] 存档 [6AFF5EFF]" + label.text + "[-]",//
                        () =>
                        {
                            VoxelEditorMastermind.instance.ReadSave(label.text);
                            fileScrollViewComponent.ShowItem();
                        },
                        () =>
                        {
                        }
                    );
                    break;
                case FileScrollViewComponent.FileOperationType.Write:
                    UIComponentMastermind.instance.ShowYesOrNo(
                          "是否[EEE12EFF]覆盖[-]存档 [6AFF5EFF]" + label.text + "[-]",//
                          () =>
                          {
                              VoxelEditorMastermind.instance.WriteSave(label.text);
                              fileScrollViewComponent.ShowItem();
                          },
                          () =>
                          {
                          }
                      );
                    break;
                case FileScrollViewComponent.FileOperationType.ReadPrefab:
                    UIComponentMastermind.instance.ShowYesOrNo(
                        "是否[EEE12EFF]读取[-] 预制 [6AFF5EFF]" + label.text + "[-]",//
                        () =>
                        {
                            VoxelEditorMastermind.instance.ReadPrefab(label.text);
                            //fileScrollViewComponent.ShowItem();
                        },
                        () =>
                        {
                        }
                    );
                    break;
                default:
                    break;
            }
        }
    }


    public void Delete()
    {
        if (label != null)
        {
            UIComponentMastermind.instance.ShowYesOrNo(
                 "是否[EEE12EFF]删除[-]存档 [6AFF5EFF]" + label.text + "[-]",//
                  () =>
                  {
                      VoxelEditorMastermind.instance.DeleteSave(label.text);
                      fileScrollViewComponent.ShowItem();
                  },
                  () =>
                  {
                  }
              );
        }
    }
    //   void Start () 
    //   {

    //}

    //void Update () 
    //   {

    //}
}
